package com.beamfield.controller.manage.process;

import com.beamfield.common.ApiResult;
import com.beamfield.controller.common.BaseController;
import com.beamfield.enums.HttpResultEnum;
import com.beamfield.modelVo.ProcObjVo;
import com.beamfield.service.manage.process.ProcPreviewService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;

/**
 * @author Zephyr
 * @Description: 工序 - 总览
 * @Date 2018/11/2
 */
@Controller
@RequestMapping("/cms/process/preview")
public class ProcessPreviewController extends BaseController {
    @RequestMapping(value = "/basic_Info")
    public ModelAndView check(){
        return new ModelAndView();
    }
    @RequestMapping(value = "/material_traceability")
    public ModelAndView materialTraceability(){
        return new ModelAndView();
    }
    @RequestMapping(value = "/proc_doc")
    public ModelAndView procDoc(){
        return new ModelAndView();
    }
    @RequestMapping(value = "/proc_quality")
    public ModelAndView procQuality(){
        return new ModelAndView();
    }

    private final ProcPreviewService procPreviewService;

    @Autowired
    public ProcessPreviewController(ProcPreviewService procPreviewService) {
        this.procPreviewService = procPreviewService;
    }

    /**
     * 获取基本信息
     * @return
     */
    @RequestMapping(value = "/getBasicInfo", method = RequestMethod.GET)
    @ResponseBody
    public ApiResult getBasicInfo(HttpServletRequest request){
        String noticeId = request.getParameter("noticeId");
        if (StringUtils.isEmpty(noticeId)){
            return new ApiResult(HttpResultEnum.MIS_PARAM.getCode(), HttpResultEnum.MIS_PARAM.getMessage());
        }
        try{
            ProcObjVo basicInfo = procPreviewService.getBasicInfo(Long.parseLong(noticeId));
            return new ApiResult(basicInfo);
        }catch (Exception e){
            e.printStackTrace();
            return new ApiResult(HttpResultEnum.EXCEPTION.getCode(), HttpResultEnum.EXCEPTION.getMessage());
        }
    }

    /**
     * 获取审核信息
     * @return
     */
    @RequestMapping(value = "/getProcQuality", method = RequestMethod.GET)
    @ResponseBody
    public ApiResult getProcQuality(HttpServletRequest request){
        String noticeId = request.getParameter("noticeId");
        Long beamId = super.getBeamId(request);
        if (StringUtils.isEmpty(noticeId)){
            return new ApiResult(HttpResultEnum.MIS_PARAM.getCode(), HttpResultEnum.MIS_PARAM.getMessage());
        }
        try{
            ProcObjVo basicInfo = procPreviewService.getProcQuality(Long.parseLong(noticeId), beamId);
            return new ApiResult(basicInfo);
        }catch (Exception e){
            e.printStackTrace();
            return new ApiResult(HttpResultEnum.EXCEPTION.getCode(), HttpResultEnum.EXCEPTION.getMessage());
        }
    }

    /**
     * 获取工序文档信息
     * @return
     */
    @RequestMapping(value = "/getProcDoc", method = RequestMethod.GET)
    @ResponseBody
    public ApiResult getProcDoc(HttpServletRequest request){
        String noticeId = request.getParameter("noticeId");
        if (StringUtils.isEmpty(noticeId)){
            return new ApiResult(HttpResultEnum.MIS_PARAM.getCode(), HttpResultEnum.MIS_PARAM.getMessage());
        }
        Long beamId = super.getBeamId(request);
        try{
            ProcObjVo basicInfo = procPreviewService.getProcDoc(Long.parseLong(noticeId), beamId);
            return new ApiResult(basicInfo);
        }catch (Exception e){
            e.printStackTrace();
            return new ApiResult(HttpResultEnum.EXCEPTION.getCode(), HttpResultEnum.EXCEPTION.getMessage());
        }
    }


    /**
     * 获取物资追溯
     * @param request
     * @return
     */
    @RequestMapping(value = "/getMaterialTrace", method = RequestMethod.GET)
    @ResponseBody
    public ApiResult getMaterialTrace(HttpServletRequest request){
        String noticeId = request.getParameter("noticeId");
        if (StringUtils.isEmpty(noticeId)){
            return new ApiResult(HttpResultEnum.MIS_PARAM.getCode(), HttpResultEnum.MIS_PARAM.getMessage());
        }
        Long beamId = super.getBeamId(request);
        try{
            ProcObjVo basicInfo = procPreviewService.getMaterialTrace(Long.parseLong(noticeId), beamId);
            return new ApiResult(basicInfo);
        }catch (Exception e){
            e.printStackTrace();
            return new ApiResult(HttpResultEnum.EXCEPTION.getCode(), HttpResultEnum.EXCEPTION.getMessage());
        }
    }
}
